package controladores;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

public class LogBdd {


    PreparedStatement pslog = null;
    Connection connlog = null;
    public int log(String user, String actividad) {
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
        } catch (ClassNotFoundException e) {
           e.printStackTrace();
        }
        try {
            connlog = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventario_control_log", "chepe", "gundam");
        } catch (SQLException e) {
          e.printStackTrace();
        }
        int flag=0;

        try{
        String SQL="";
        SQL=SQL+"INSERT INTO log_bdd (id,usuario,actividad,tiempo)";
        SQL=SQL+" VALUES(?,?,?,?);";

        pslog = connlog.prepareStatement(SQL);

        pslog.setInt(1, 0);
        pslog.setString(2, user);
        pslog.setString(3, actividad);
        pslog.setTimestamp(4, new java.sql.Timestamp(new java.util.Date().getTime()));
        
        flag=pslog.executeUpdate();

        }catch(Exception e){
           System.out.print("Error de close");
        
        }

       return flag;
    }
    public int logN(String user, String lugar) {
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
        } catch (ClassNotFoundException e) {
           e.printStackTrace();
        }
        try {
            connlog = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventario_control_log", "chepe", "gundam");
        } catch (SQLException e) {
          e.printStackTrace();
        }
        int flag=0;

        try{
        String SQL="";
        SQL=SQL+"INSERT INTO log_accesos (id,usuario,lugar,Tacceso)";
        SQL=SQL+" VALUES(?,?,?,?);";

        pslog = connlog.prepareStatement(SQL);

        pslog.setInt(1, 0);
        pslog.setString(2, user);
        pslog.setString(3, lugar);
        pslog.setTimestamp(4, new java.sql.Timestamp(new java.util.Date().getTime()));

        flag=pslog.executeUpdate();

        }catch(Exception e){
            e.printStackTrace();
           System.out.print("Error de close");

        }

       return flag;
    }
    public static void  main(String[]args){

       LogBdd uj = new LogBdd();
    


          System.out.print( uj.logN("chepe", "usuario/nuevo.jsp"));






   }
}